<DOCTYPE html>
    <html>
        <head lang="en">
                <meta charset="UTF-8">
        </head>
        <script>
        var rangeObj =document.createRange();
        function selectRangeConents(){
            var div=document.getElementById("div");
            rangeObj.selectNode(div);
            rangeObj.detach();

        }
        function unselect(){
            rangeObj.collapse(false);
        }
        function showRange(){
            alert(rangeObj.toString());
        }
        </script>
        <body>
            <div id="div" style="background-color:blueviolet;width:
            300px;height:50px;">元素

            </div>
            <button onclick="selectRangeConents()">选择元素</button>
            <button onclick="unselect()">取消元素</button>
            <button onclick="showRange()">显示range内容</button>  
</body>
    </html>